A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
The present invention relates generally to the use of flash memory for the storage of data. More particularly the invention relates to methods for erasing a flash memory, for writing data to a flash memory, and for reading data from a flash memory, all with improved data integrity.
A flash memory generally consists of a number of sectors of memory locations. The number of bytes of data in a sector and in the entire component varies greatly, depending on the particular flash memory component used. For example, a flash memory component may contain 2 megabytes (MB) of memory and it may be divided into 32 sectors, with each sector containing 64 kilobytes (KB) of memory. The most basic functions performed on a flash memory include writing data, reading data, and erasing data. Flash memory may only be erased an entire sector at a time. After a sector of flash memory is erased, the entire sector contains all binary ones. The flash memory may then be written or programmed by changing selected bits to a binary zero. Flash memory may generally be written or read a single byte at a time. The preferred embodiment of the present invention includes functions for erasing a sector of a flash memory component, as well as functions for allocating, writing, committing, reading, and freeing portions of a sector of a flash memory component. These portions of the flash memory will be referred to as xe2x80x9cblocks of data.xe2x80x9d
Flash memory is generally very reliable and consistent, in that all bits of a sector are generally changed to a binary one upon erasure, and, after data has been programmed into a flash memory, it may be read back out accurately and consistently, over a long period of time. However, it is well known in the art that the data in a flash memory may be corrupted if power to the flash memory is disrupted while the memory is being erased or programmed. Power disruptions may occur for various reasons, such as a user intentionally or inadvertently shutting off the power to a device, a battery running out of energy, or a failure in the public alternating current power system. If a power disruption occurs during the erasure of a sector, the integrity of the data in the entire sector may be compromised. If a power disruption occurs while a portion of the flash memory is being written, any bit that was to be cleared to a binary zero during the write operation may or may not have been cleared. In addition, if a power disruption occurs while writing to an Intel StrataFlash(trademark) memory, a bit that is adjacent to a bit that is being cleared may also be changed either from a binary one to a binary zero, or from a binary zero to a binary one. This is due to the technology of the StrataFlash(trademark) memory, which enables the storage of two bits in a single memory cell. Thus, if a power disruption occurs while writing a zero to either bit of a StrataFlash(trademark) memory cell, either one or both bits may be a binary zero or a binary one.
Many existing devices and systems that contain flash memory have little or no safeguards against the possibility of the data in the memory being corrupted upon power disruption. A system and method are needed for controlling, programming, and accessing a flash memory that will improve the reliability of the flash memory data, in the event of a power disruption during erase and program operations.
The present invention comprises a method of reclaiming data from a first data sector of a flash memory to a second data sector of a flash memory in a manner that enables for a resumption of the reclaiming method in the event of a power interruption during the method. This first method comprises the steps of writing a first value to a sector state register for the first data sector to indicate that the first data sector is in a first reclaiming state, writing a second value to a destination sector register for the first data sector to indicate that the first data sector will be reclaimed to the second data sector, writing a third value to the sector state register for the first data sector to indicate that the first data sector is in a second reclaiming state, erasing the second data sector, copying valid data from the first data sector to the second data sector, writing a fourth value to the sector state register for the second data sector to indicate that the valid data from the first data sector has been successfully copied to the second data sector, and writing a fifth value to the sector state register for the first data sector to indicate that the first data sector has been successfully reclaimed to the second data sector. In this method, reclaiming from the first data sector to the second data sector is permissible, while reclaiming from the second data sector to the first data sector is not permissible.
In one embodiment of the invention, the sector state registers and the destination sector register reside in the flash memory. In another embodiment, each of the sector state registers and the destination sector register comprises a plurality of memory cells, and each memory cell has a plurality of bits, wherein writing to a first bit of a memory cell may affect one or more other bits in the memory cell in case of a power interruption, and only one bit is used in each of the plurality of memory cells of the sector state registers and the destination sector register. In another embodiment, the second value is an encoded sector number for the second data sector. In yet another embodiment, the encoded sector number is obtained by duplicating each bit of a binary sector number for the second data sector. In another embodiment, a possible reclaiming source is a permissible reclaiming source for a reclaiming destination if:
(RDxe2x88x92RS+NS) % NS less than NS/2
wherein RD is a sector number of the reclaiming destination, RS is a sector number of the possible reclaiming source, NS is a total number of data sectors in the flash memory, and xe2x80x9c%xe2x80x9d indicates a mathematical operation of dividing a first number by a second number and taking the remainder.
The present invention also comprises a method of maintaining a plurality of status bits in a flash memory component so that no more than one status bit may be corrupted at a time, wherein the flash memory component has a plurality of memory cells that each has a plurality of bits, and wherein writing to a first bit of a memory cell may affect one or more other bits in the memory cell in case of a power interruption. This second method comprises the steps of using a different memory cell for each status bit, selecting a first bit from a memory cell for use as the status bit for that memory cell and not using the rest of the plurality of bits in the memory cell, and writing each status bit in a different write operation. In more specific embodiments of this second method, the plurality of status bits may comprise a sector state register or a block state register. Also, the unused bits in a memory cell may be cleared to a binary zero or left at a binary one.
The present invention also comprises a method of encoding a sector number for storage in a destination sector register in a flash memory component, wherein the flash memory component comprises a plurality of memory cells that each has a plurality of bits, and wherein writing to a first bit in a memory cell may affect one or more other bits in the memory cell in case of a power interruption. This third method comprises the steps of representing the destination sector number in binary format and duplicating each bit of the binary representation of the destination sector number for storage in the destination sector register.
The present invention also comprises a method of maintaining a plurality of versions of a set of data in a plurality of data blocks in memory, each of said data blocks having a block version register. This fourth method comprises the steps of setting a global version register to an initial value, changing the value in the global version register each time a commit function is performed to commit written data blocks into memory, and copying the value from the global version register to the block version register for a data block, when the data block is written with data.
In one embodiment of this fourth method, the global version register is located in random access memory (RAM). In another embodiment, the global version register is initially cleared to zero and the value in the global version register is incremented each time a commit function is performed. In other embodiments, when power is turned on after a power interruption, a new value is determined for the global version register that is the highest value in a block version register for any written data block that has been committed into memory and this new value is written into the global version register. Then, any data block, that has a value in the block version register for that data block that is higher than the value in the global version register, may be marked to indicate that the data block has invalid data. Then, any data block, that has a value in the block version register for that data block that is the same as the value in the global version register, may be committed into memory. Then, any committed data block that has become obsolete may be marked to indicate that the data block has invalid data. Also, before the global version register is set to a value that is the highest value in a block version register for any written data block that has been committed into memory, the method may comprise the steps of determining whether a previous reclaiming operation was interrupted by the power interruption, and, if a previous reclaiming operation were interrupted by the power interruption, completing the interrupted reclaiming operation.
The present invention also comprises a system for managing data in a flash memory, the flash memory comprising a first plurality of data sectors, each of said first plurality of data sectors comprising a second plurality of data blocks. The system comprises a processor for executing one or more functions for managing the data in the flash memory, a reclaiming function for copying a plurality of valid data from a reclaiming source sector to a reclaiming destination sector and for erasing the reclaiming source sector, a first plurality of sector state registers for indicating a state for each of said first plurality of sectors, wherein a sector may be in a used state, a first reclaiming state, a second reclaiming state or a reclaimed state, and a destination block register for indicating a reclaiming destination sector to which a reclaiming source sector is being reclaimed during a reclaiming operation. In this embodiment, the reclaiming function sets the sector state register for a reclaiming source sector to indicate that the reclaiming source sector is in the first reclaiming state, then sets the destination block register to indicate a reclaiming destination sector, then sets the sector state register for the reclaiming source sector to indicate that the reclaiming source sector is in the second reclaiming state, then erases the reclaiming destination sector, then copies a plurality of valid data from the reclaiming source sector to the reclaiming destination sector, then sets the sector state register for the reclaiming destination sector to indicate that the reclaiming destination sector is in the used state, and then sets the sector state register for the reclaiming source sector to indicate that the reclaiming source sector is in the reclaimed state. Also, in this embodiment, permissible combinations of a reclaiming source sector and a reclaiming destination sector are mutually exclusive. Also, if power is interrupted during a reclaiming operation, the reclaiming operation may be resumed when power is supplied again.
In one embodiment of this system, the system comprises a first plurality of destination block registers for indicating a reclaiming destination sector to which each of said first plurality of sectors is being reclaimed when each of said first plurality of sectors is a reclaiming source sector in a reclaiming operation. In another embodiment of this system, a possible reclaiming source sector is a permissible reclaiming source sector for a reclaiming destination sector if:
(RDxe2x88x92RS+NS) % NS less than NS/2
wherein RD is a sector number of the reclaiming destination sector, RS is a sector number of the possible reclaiming source sector, NS is the number of data sectors in the first plurality of data sectors, and xe2x80x9c%xe2x80x9d indicates a mathematical operation of dividing a first number by a second number and taking the remainder.